package com.joycessh.dao.impl;

import java.sql.*;
import com.joycessh.dao.ITopicDao;
import com.joycessh.util.DBConnectionManager;

public class TopicDaoImpl implements ITopicDao {
	
	/**
	 * @author joycessh
	 * ITopicDao接口的实现类
	 */
	
	DBConnectionManager dcm = null;
	Connection conn = null;
	Statement  stmt = null;
	ResultSet rs = null;
	PreparedStatement prepstmt = null;
	String sqlStr ="";
	Boolean flag = false;
	int effectLines = 0;
	
	//方法：创建贴子
	@Override
	public boolean createTopic(String title, String content, String author, Timestamp createDate) throws SQLException {
		dcm = new DBConnectionManager();
		conn = dcm.getConnection();
		flag = false;
		
		sqlStr = "insert into t_topic(title, content, author, create_date) values(?, ?, ?, ?)";
		try {
			prepstmt = conn.prepareStatement(sqlStr);
			prepstmt.setString(1, title);
			prepstmt.setString(2, content);
			prepstmt.setString(3, author);
			prepstmt.setTimestamp(4,  createDate);
			effectLines = prepstmt.executeUpdate();
			if (effectLines != 0) {
				flag = true;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		prepstmt.close();
		conn.close();
		return flag;
	}

}
